/*
    Copyright (C) 2010-2011 AmigaVR
    
    This file is part of AmigaVR.
    Written by Ketfi-Chérif Mehdi <ketficherif.mehdi@gmail.com>

    AmigaVR is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AmigaVR is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AmigaVR.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "global.h"

void rtc_init ( void )
{
	RTC.CTRL = 0x01;
	OSC.CTRL = OSC.CTRL|0x04;
	CLK.RTCCTRL = CLK.RTCCTRL|0x05;
}

uint16_t rtc_get_ticks ( void )
{
	while ( (RTC.STATUS&0x01) );
	return ((RTC.CNTH<<8)+RTC.CNTL);
}

void rtc_set ( uint16_t count )
{
	while ( (RTC.STATUS&0x01) );
	RTC.CNTL = count&0x00FF;
	RTC.CNTH = count&0xFF00;
}

void rtc_pause ( void )
{
	RTC.CTRL = 0x00;
}

void rtc_start ( void )
{
	RTC.CTRL = 0x01;
}

